﻿using Rbac.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rbac.Domain.Impl
{
	public class Repository<T>:IRepository<T> where T : class
	{
		private readonly RbacContext db;
		public Repository(RbacContext db)
		{
			this.db = db;
		}

		public int Add(T entity)
		{
			 db.Set<T>().Add(entity);
			 return db.SaveChanges();
		}

		public int Delete(params T[] entity)
		{
			db.Set<T>().RemoveRange(entity);
			return db.SaveChanges();
		}

		public IQueryable<T> GetAll()
		{
			return db.Set<T>().AsQueryable();
		}

		public int Update(T entity)
		{
			db.Set<T>().Update(entity);
			return db.SaveChanges();
		}
	}
}
